//
//  com_mainViewController.m
//  car
//
//  Created by chenxu on 4/14/15.
//  Copyright (c) 2015 chenxu. All rights reserved.
//

#import "com_mainViewController.h"
#import "NetAPIManager.h"
#import "com_ordersViewController.h"
#import "BLogin.h"
@interface com_mainViewController ()

@end

@implementation com_mainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    if ([BLogin isLogin]) {
        _usernameLabel.text = [_usernameLabel.text stringByAppendingString:[BLogin curCompany].Businessname];
        _companynameLabel.text = [_companynameLabel.text stringByAppendingString:[BLogin curCompany].Company];
    }
    else{
        [self performSegueWithIdentifier:@"logout" sender:self];
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 1 || indexPath.row == 2 ) {
        [self performSegueWithIdentifier:@"2Orders" sender:indexPath];
    }
}

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    
    if ([segue.identifier  isEqual: @"2Orders"]) {
        NSIndexPath* indexpath = (NSIndexPath*)sender;
        com_ordersViewController * vc = [ segue destinationViewController];

        if (indexpath.row == 1 ) {
            vc.finished = YES;
        }
        else{
            vc.finished = NO;
        }
    }
   
}


- (IBAction)logout:(id)sender {
    [[NetAPIManager sharedManager]company_Logout_WithParams:[[BLogin curCompany]toNameParams] andBlock:^(id data, NSError *error) {
        [self performSegueWithIdentifier:@"logout" sender:self];
    }];
}
@end
